<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>请输入</h3>
    <input type="text">
    <div>
        
        已经猜的次数: <span id="guessCount">0</span>
    </div>
    <div>
        结果是: <span id="result"></span>
    </div>
    <button>猜</button>

    <script>

        let input = document.querySelector('input');
        let button = document.querySelector('button');
        let guessCount = document.querySelector('#guessCount');
        let result = document.querySelector('#result');
        //生成随机数 1~100
        let toGuess = parseInt(Math.random()*100 + 1);
        console.log(toGuess);

        //给按钮加点击事件
       button.onclick = function() {
        let value = parseInt(input.value);
        if(value < toGuess) {
            result.innerHTML = '低了';
        } else if(value > toGuess) {
            result.innerHTML = '高了';
        } else if( value == toGuess) {
            result.innerHTML = '猜对了';
        }

        let guessCountValue = parseInt(guessCount.innerHTML) + 1;
        guessCount.innerHTML = guessCountValue;
       }


    </script>
</body>
</html>